package Work1;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class TestServer {
    public static void main(String[] args) {

        try {
            ServerSocket ss = new ServerSocket(6588);
            System.out.println("服务端等待链接...");
            Socket socket = ss.accept();
            System.out.println("链接成功...");
            InputStream is = socket.getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            FileOutputStream fos = new FileOutputStream(new File("D:故乡.txt"));
            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));
            while (true) {
                String s = br.readLine();
                if (s == null) {
                    break;
                }
                bw.write(s);
                bw.newLine();
                System.out.println(s);
            }
            br.close();
            bw.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }


}
